package com.dymall.payment.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dymall.payment.domain.pojo.CreditCard;
import com.dymall.payment.domain.dto.CreditCardInfo;
import org.apache.ibatis.annotations.*;

public interface CreditCardMapper extends BaseMapper<CreditCard> {
    @Select("select * from creditcard where user_id = #{userId}")
    @Results(id = "creditCardResultMap", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "credit_card_number", property = "cardNum"),
            @Result(column = "credit_card_cvv", property = "cardCvv"),
            @Result(column = "credit_card_exp_year", property = "expYear"),
            @Result(column = "credit_card_exp_month", property = "expMonth")
    })
    CreditCard getUserCreditCard(Long userId);

    @Insert("insert into creditcard (user_id,credit_card_number, credit_card_cvv, credit_card_exp_year, credit_card_exp_month) " +
            "values (#{userId},#{cardInfo.cardNum},#{cardInfo.cardCvv},#{cardInfo.expYear},#{cardInfo.expMonth});")
    void insertCard(@Param("userId") Long userId, @Param("cardInfo") CreditCardInfo cardInfo);
}
